package functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator;

import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program.ArgumentMap;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program.Argument;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program.Program;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.program.ProgramType;
import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.utils.DateUtils;
import java.io.File;

/**
 * The main class for running the application.
 * @author Jamie MacPherson
 */
public class SemanticSimilarityProgram {

    /**
     * This method runs the application.
     * Certain arguments are required. See the <code>Argument</code> class for details.
     * @param args the command line arguments.
     * 
     */
    public void run(String[] args) {
        ArgumentMap argumentMap = new ArgumentMap(args);

        ProgramType programType = (ProgramType) argumentMap.get(Argument.PROGRAM);
        if (programType == null) {
            System.out.println("you must specify what program you wish to run (either 'geneSetAnalysis' or 'similarities'), with the -p argument");
            System.out.println("exiting program");
            System.exit(0);
        }

        Program program = programType.getProgram();
        System.out.println("started running " + programType.getTag() + " program at " + DateUtils.now());
        try {
            program.setArgumentMap(argumentMap);
        } catch (IllegalArgumentException exception) {
            System.out.println("exiting program");
            exception.printStackTrace();
            System.exit(0);
        }
        program.run();
        System.out.println("finished running " + programType.getTag() + " program at " + DateUtils.now());
    }

    public void runClusterSetAnalysis() {
        File dataFileFolder = new File("/Users/jamie/Dropbox/monkeys/GO/semanticSimilarity/geneSets");
        int i=1;
        for (File geneFile : dataFileFolder.listFiles()) {
            File out = new File("/Users/jamie/Dropbox/monkeys/GO/semanticSimilarity/results/clusters/results_" + i+"/");
            try{
                if(out.mkdir()){
                    System.out.println("created file");
                } else {
                    System.out.println("failed to make directory");
                }
            } catch(Exception ex){
                ex.printStackTrace();
            }

            String[] args = new String[10];
            args[0] = "-p";
            args[1] = "geneSetAnalysis";
            args[2] = "-s";
            args[3] = "/Users/jamie/Dropbox/monkeys/GO/semanticSimilarity/geneSimilarities/similarities_P.txt";
            args[4] = "-d";
            args[5] = geneFile.getAbsolutePath();
            args[6] = "-t";
            args[7] = "4";
            args[8] = "-r";
            args[9] = out.getAbsolutePath();
            run(args);
            i++;
        }
    }

    public void runSimilaritiesProgram() {
        String[] args = new String[10];
        args[0] = "-p";
        args[1] = "similarities";

        args[2] = "-s";
        args[3] = "/Users/jamie/Dropbox/monkeys/GO/semanticSimilarity/geneSimilarities/similarities_F.txt";

        args[4] = "-o";
        args[5] = "F";

        args[6] = "-g";
        args[7] = "/Users/jamie/Dropbox/monkeys/GO/annotations/gene_association.goa_human";

        args[8] = "-b";
        args[9] = "/Users/jamie/Dropbox/monkeys/GO/annotations/gene_ontology.obo";

        run(args);

    }
}
